//
//  WQHomeDeviceListCell.m
//  WisdomQuestor
//
//  Created by 纪景城 on 2024/12/18.
//

#import "WQHomeDeviceListCell.h"

@interface WQHomeDeviceListCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation WQHomeDeviceListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.clipsToBounds = YES;
        self.backgroundColor = UIColor.clearColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubviews:[NSArray arrayWithObjects:self.jk_collectionView, nil]];
        [self fragmentUI_ViewSet];
    }
    return self;
}

#pragma mark ------- UICollectionViewDelegate -------

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
//    return self.deviceArray.count;
    return 2;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    WQDeviceStatusCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[WQDeviceStatusCollectionCell kj_runtimeClassName] forIndexPath:indexPath];
    
    return cell;
}

#pragma mark ------- Lazy Methods -------

- (void)fragmentUI_ViewSet {
    [self.jk_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kFragmemtFloat(10));
        make.right.equalTo(self.contentView.mas_right).offset(-kFragmemtFloat(10));
        make.top.bottom.equalTo(self.contentView);
    }];
}

- (UICollectionView *)jk_collectionView {
    if (!_jk_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake((kScreen_Width - kFragmemtFloat(33)) / 2, kFragmemtFloat(150));
        layout.minimumLineSpacing = 10;
        layout.minimumInteritemSpacing = 10;
//        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _jk_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:layout];
        _jk_collectionView.backgroundColor = [UIColor clearColor];
        _jk_collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _jk_collectionView.showsHorizontalScrollIndicator = NO;
        _jk_collectionView.showsVerticalScrollIndicator = NO;
        _jk_collectionView.scrollEnabled = NO;
        _jk_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        _jk_collectionView.dataSource = self;
        _jk_collectionView.delegate = self;
        [_jk_collectionView registerClass:[WQDeviceStatusCollectionCell class] forCellWithReuseIdentifier:[WQDeviceStatusCollectionCell kj_runtimeClassName]];
    }
    return _jk_collectionView;
}

@end
